package com.ai.imagetext.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.hibernate.annotations.CreationTimestamp;

import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Entity
@Table(name = "image_tags", uniqueConstraints = {
    @UniqueConstraint(columnNames = {"image_id", "tag_id"})
})
@EqualsAndHashCode(callSuper = false)
public class ImageTag {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "image_id", nullable = false)
    @ToString.Exclude
    @JsonIgnore
    private Image image;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "tag_id", nullable = false)
    @ToString.Exclude
    @JsonIgnore
    private Tag tag;

    @Column(precision = 10)
    private BigDecimal confidence;
    
    @Enumerated(EnumType.STRING)
    private TagSource source = TagSource.AI;
    
    @CreationTimestamp
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    public enum TagSource {
        AI, MANUAL
    }
}